<template>
  <el-dialog
    :append-to-body="true"
    :close-on-click-modal="false"
    :before-close="cancel"
    :visible.sync="dialog"
    :title="0 ? '新增' : '编辑'"
  >
    <el-form ref="form1" :model="form"  >
        <template>
          <el-transfer v-model="form.ids"  :props="{
       key: 'id',      
      label: 'brandName'
    }" :data="data" style="margin-left: 30px;"></el-transfer>
        </template>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {getAllBrand,relatedBrand} from '@/api/storeTemplate'
import CRUD, { presenter, header, form, crud } from "@crud/crud";
export default {
    data() {
      return {
        data: [],
        loading: false,
        dialog: false,
        form: {
          id: '',
          ids:[]
        },
      };
    },
  methods: {
    cancel() {
      this.resetForm();
    },
    doSubmit() {
      this.loading = false;
      const template={id:this.form.id,brands:(this.form.ids).join(",")}
  console.log('template',template)
      relatedBrand(template)
        .then((res) => {
          this.resetForm();
          this.$notify({
            title: "修改成功",
            type: "success",
            duration: 2500,
          });
          this.loading = false;
          console.log("doSubmit -> this", this);
          this.$parent.crud.toQuery();
        })
        .catch((err) => {
          this.loading = false;
          console.log(err);
        });
    },
   
    // 提交前做的操作
    [CRUD.HOOK.afterValidateCU](crud) {
      if (this.roleList.length === 0) {
        this.$message({
          message: "角色不能为空",
          type: "warning",
        });
        return false;
      }
      // crud.form.roleList = userRoles;
      return true;
    },
    resetForm() {
      this.dialog = false;
      this.$refs["form1"].resetFields();
      this.form = {
        id: '',
          ids:[]
      };
    },
  },
};
</script>

<style scoped>
</style>
